package cn.wj.base.util;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DateUtils {
	/** 取上月第一天或最后一天 */
	public static String[] getLastMonth() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar calendar = Calendar.getInstance();
		// 取得现在时间
		calendar.setTime(new Date());
		// 取得上一个时间
		calendar.set(Calendar.MONDAY, calendar.get(Calendar.MONDAY) - 1);
		// 取得上一个月的下一天
		// calendar.set(Calendar.DAY_OF_MONTH,
		// calendar.get(Calendar.DAY_OF_MONTH) + 1);
		// System.out.println(sdf.format(calendar.getTime()));
		calendar.set(Calendar.DAY_OF_MONTH, 1);
		String start = sdf.format(calendar.getTime());
		calendar.roll(Calendar.DAY_OF_MONTH, -1);
		String end = sdf.format(calendar.getTime());
		return new String[] { start, end };
	}

	/** 取本月第一天或最后一天 */
	public static String[] getThisMonth() {
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
		Calendar cal = Calendar.getInstance();
		cal.setTime(new Date());
		cal.set(Calendar.DAY_OF_MONTH, 1);
		String start = sdf.format(cal.getTime());
		cal.roll(Calendar.DAY_OF_MONTH, -1);
		String end = sdf.format(cal.getTime());
		return new String[] { start, end };
	}
}
